// import { shareCoinToCust } from "@/server/api";
export function formatDate() {
  let date = new Date();
  let seperator1 = "-";
  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  let strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  let currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;
}
export function getCookie(cname) {
  var name = cname + "=";
  var ca = document.cookie.split(";");
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i].trim();
    if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
  }
  return "";
}
export function setCookie(name, value) {
  var exp = new Date();
  exp.setTime(exp.getTime() + 60 * 60 * 1000);
  document.cookie =
    name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}

export function delCookie(name) {
  //为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
  var date = new Date();
  date.setTime(date.getTime() - 10000);
  document.cookie = name + "=a; expires=" + date.toGMTString();
}

export function createFormData(params) {
  const formData = new FormData();
  if (params) {
    for (let k in params) {
      formData.append(k, params[k]);
    }
  }

  return formData;
}

export function GetUrlParame(parameName) {
  /// 获取地址栏指定参数的值
  /// <param name="parameName">参数名</param>
  // 获取url中跟在问号后面的部分
  var parames = window.location.href;
  // 检测参数是否存在
  if (parames.indexOf(parameName) > -1) {
    var parameValue = "";
    parameValue = parames.substring(
      parames.indexOf(parameName),
      parames.length
    );
    // 检测后面是否还有参数

    if (parameValue.indexOf("&") > -1) {
      // 去除后面多余的参数, 得到最终 parameName=parameValue 形式的值
      parameValue = parameValue.substring(0, parameValue.indexOf("&"));

      if (parameName == "state" && parameValue.indexOf("#") > -1) {
        parameValue = parameValue.substring(0, parameValue.indexOf("#"));
      }
      // 去掉参数名, 得到最终纯值字符串
    }
    parameValue = parameValue.replace(parameName + "=", "");
    return parameValue;
  } else {
    return "";
  }
}
